
package com.caration.shell;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;

//Restart Application
public class Restart extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle bundle = getIntent().getExtras();
        if (!bundle.containsKey("pid"))
            finish();
        Thread restartThread = new Thread() {
            @Override
            public void run() {
                do {

                    try {
                        Process.killProcess(bundle.getInt("pid"));
                        dismissDialog(0);
                        finish();
                        Intent intent = new Intent(Restart.this, Home.class);
                        startActivity(intent);
                        return;
                    } catch (Exception e) {
                        try {
                            Thread.sleep(2000L);
                        } catch (InterruptedException interruptedException) {
                            interruptedException.printStackTrace();
                        }
                    }
                } while (true);
            }
        };
        showDialog(0);
        restartThread.start();
    }

    protected Dialog onCreateDialog(int index) {
        ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getString(R.string.mn_restartshell));
        return dialog;
    }

    public void onDestroy() {
        try {
            System.exit(0);
        } catch (Exception ex) {
        }
        super.onDestroy();
    }
}
